package top.kaoshanji.p3ch13a;

import java.security.AccessController;
import java.security.PrivilegedAction;

/**
 * author kaoshanji
 * ^_^
 * create time 2025/2/8 09:38
 */
public class GetSystemProperty {

    // 代码清单-p3ch13a-420页a：获取系统属性的方法示例
    public static String get(String property) {
        return System.getProperty(property);
    }

    // 代码清单-p3ch13a-421页a：使用特权动作获取系统属性
    public static String getWithPrivilege(final String property) {
        return AccessController.doPrivileged(new PrivilegedAction<String>() {
            @Override
            public String run() {
                return System.getProperty(property);
            }
        });
    }



}
